package com.promis.party.ui.home;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.party.ui.home.homebanner.answerwall.MyAnswerActivity;
import com.promis.party.ui.home.homebanner.mylearn.MyLearnActivity;
import com.promis.party.ui.home.homebanner.mywork.MyWorkActivity;
import com.promis.party.ui.home.homebanner.questionwall.MyQuestionsActivity;
import com.promis.party.ui.home.homebanner.threemmeetingonecourse.ThreeMeetingOneCourseActivity;
import com.promis.widget.ImageTextView;
import com.promis.widget.listener.OnAvoidMultiClickListener;

/**
 * Created by jidanbo on 2018/2/2.
 */

public class HomeFragmentBanner extends Fragment {

    private ContextHelper contextHelper;

    private LinearLayout rootLayout;
    private ImageTextView imageTextViewWork;
    private ImageTextView imageTextViewThreeMeetingOneCourse;
    private ImageTextView imageTextViewLearning;
    private ImageTextView imageTextViewQuestions;
    private ImageTextView imageTextViewEchoWall;

    private int position;

    public final static HomeFragmentBanner newInstance(int position) {
        HomeFragmentBanner fragment = new HomeFragmentBanner();
        fragment.position = position;
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootLayout = (LinearLayout) inflater.inflate(R.layout.fragment_home_banner, null, false);

        imageTextViewWork = rootLayout.findViewById(R.id.fragment_home_banner_txtv_work);
        imageTextViewThreeMeetingOneCourse = rootLayout.findViewById(R.id.fragment_home_banner_txtv_threemeeting_onecourse);
        imageTextViewLearning = rootLayout.findViewById(R.id.fragment_home_banner_txtv_learn);
        imageTextViewQuestions = rootLayout.findViewById(R.id.fragment_home_banner_txtv_question);
        imageTextViewEchoWall = rootLayout.findViewById(R.id.fragment_home_banner_txtv_echo_wall);

        if(position == 0){
            imageTextViewWork.setVisibility(View.VISIBLE);
            imageTextViewEchoWall.setVisibility(View.GONE);
        }else{
            imageTextViewWork.setVisibility(View.GONE);
            imageTextViewEchoWall.setVisibility(View.VISIBLE);
        }

        initData();
        initListener();
        return rootLayout;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    private void initData() {
        contextHelper = new ContextHelper(getContext());
    }

    private void initListener() {
        imageTextViewWork.setOnClickListener(new OnAvoidMultiClickListener() {
            @Override
            public void onAvoidMultiClick(View v) {
                Intent intent = new Intent(getContext(), MyWorkActivity.class);
                startActivity(intent);
            }
        });

        imageTextViewThreeMeetingOneCourse.setOnClickListener(new OnAvoidMultiClickListener() {
            @Override
            public void onAvoidMultiClick(View v) {
                Intent intent = new Intent(getContext(), ThreeMeetingOneCourseActivity.class);
                startActivity(intent);
            }
        });

        imageTextViewLearning.setOnClickListener(new OnAvoidMultiClickListener() {
            @Override
            public void onAvoidMultiClick(View v) {
                Intent intent = new Intent(getContext(), MyLearnActivity.class);
                startActivity(intent);
            }
        });

        imageTextViewQuestions.setOnClickListener(new OnAvoidMultiClickListener() {
            @Override
            public void onAvoidMultiClick(View v) {
                Intent intent = new Intent(getContext(), MyQuestionsActivity.class);
                startActivity(intent);
            }
        });

        imageTextViewEchoWall.setOnClickListener(new OnAvoidMultiClickListener() {
            @Override
            public void onAvoidMultiClick(View v) {
                Intent intent = new Intent(getContext(), MyAnswerActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
            }
        }
    }

}
